<?php
namespace Home\Model;

class UserModel extends CommonModel{
    
    public function changeUserScore($uid,$score=0,$type){
        $ScoreTable = M('Score');
        $create_date = date('Y-m-d');
        $row = $ScoreTable->where(array('create_date'=>$create_date,'uid'=>$uid,'type'=>$type))->find();
        if($row) return;
        
        $ScoreTable->add(array('create_date'=>$create_date,'uid'=>$uid,'type'=>$type,'score'=>$score));
        if($score > 0){
            $this->where(array('id'=>$uid))->setInc('score',$score); //用户积分增加
        }else{
            $this->where(array('id'=>$uid))->setDec('score',(0-$score)); //用户积分减少
        }
    }
    
}